Imports System.Data
Imports System.Data.SqlClient
Imports CAPA_Utilitarios
Public Class PickeadorDatos

    'Se crea una instancia unica para las conexiones
    Dim conex As Conexion = Conexion.getInstance()

    Sub actualizarBandejaXPickeador(ByVal codPick As String, ByVal codBan As String, ByVal tipo As String, ByVal fecha As String)
        Dim query As String = ""
        Dim valor As Boolean = False
        Dim con As SqlConnection = conex.obtenerConexion()

        Try
            con.Open()

            If tipo = "A" Then
                query = "UPDATE Usuario " & _
                        "SET BAN_Codigo = @bandeja, USU_FecBandeja = '" & fecha & "' " & _
                        "WHERE USU_Codigo = @pick " & _
                        "AND USU_Activo = '1'"
            Else
                query = "UPDATE PersonaPerfil " & _
                        "SET Usuario = NULL " & _
                        "WHERE USU_Codigo = @pick " & _
                        "AND USU_Activo = '1'"
            End If

            Dim comando As New SqlCommand(query, con)
            With comando
                .Parameters.AddWithValue("@bandeja", codBan)
                .Parameters.AddWithValue("@pick", codPick)
                .ExecuteNonQuery()
            End With

            valor = True
        Catch ex As Exception
            valor = False
        Finally
            con.Close()
        End Try
    End Sub

    Function eliminarBandejaXPickeador(ByVal codPick As String, ByVal codCia As String, ByVal codSuc As String) As Boolean
        Dim valor As Boolean = False
        Dim con As SqlConnection = conex.obtenerConexion()
        Try
            con.Open()

            Dim query As String = "UPDATE Usuario " & _
                                  "SET BAN_Codigo = NULL, USU_FecBandeja = NULL " & _
                                  "WHERE CIA = @cia " & _
                                  "AND SUC_Codigo = @suc " & _
                                  "AND USU_Codigo = @pick " & _
                                  "AND USU_Activo = '1'"

            Dim comando As New SqlCommand(query, con)
            With comando
                .CommandText = query
                .Parameters.AddWithValue("@pick", codPick)
                .Parameters.AddWithValue("@cia", codCia)
                .Parameters.AddWithValue("@suc", codSuc)
                .ExecuteNonQuery()
            End With

            valor = True
        Catch ex As Exception
            valor = False
        Finally
            con.Close()
        End Try

        Return valor
    End Function

End Class
